package leader.action;

import java.util.ArrayList;
import java.util.List;

import leader.service.DirectAwardService;
import leader.service.DirectProjectService;
import leader.service.DirectTeacherService;
import leader.tool.JTableDefine;
import teacher.bean.Award;
import teacher.bean.Project;
import teacher.bean.Teacher;
import tools.StringDate;

import com.opensymphony.xwork2.ActionContext;

public class DirectAwardPrintAction {
	private int flag;
	private String datedown;
	private String dateup;
	private String awaName;
	
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	public String getDatedown() {
		return datedown;
	}
	public void setDatedown(String datedown) {
		this.datedown = datedown;
	}
	public String getDateup() {
		return dateup;
	}
	public void setDateup(String dateup) {
		this.dateup = dateup;
	}
	public String getAwaName() {
		return awaName;
	}
	public void setAwaName(String awaName) {
		this.awaName = awaName;
	}
	public String execute() {
		Teacher lea=(Teacher) ActionContext.getContext().getSession().get("leader");
		DirectTeacherService DT = new DirectTeacherService();
		List<Award> lists = new ArrayList<Award>();
		DirectAwardService DP = new DirectAwardService();
		System.out.println("========="+flag);
		if(0 == flag) {
			lists = DP.selectAllDirectAward(lea);
		}
		if(1 == flag) {
			StringDate date = new StringDate();
			lists = DP.selectDirectAwardByTime(date.StringToDate(datedown),date.StringToDate(dateup), lea);
		}
		if(2 == flag) {
			lists = DP.selectAwardLikeName(awaName, lea);
		}
		if(3 == flag) {
			Award awa = new Award();
			awa.setState(0);
			lists = DP.selectDirectAwardByState(lea, awa);
		}
		System.out.println(lists.size());
		String[][] columnNames = new String[lists.size()+1][7];		
		columnNames[0] = new String[]{"编号","名称","获奖人员","通讯人员","获奖级别","获奖日期","授奖单位"};
		for(int i=1;i<lists.size()+1;i++) {
			Award award = lists.get(i-1);
			columnNames[i][0] = String.valueOf(i);
			columnNames[i][1] = award.getName();
			columnNames[i][2] = award.getPeople();
			Teacher tea = new Teacher();
			tea.setTeaId(award.getTeaId());			
			columnNames[i][3] = DT.selectTeacherById(tea).getName();
			columnNames[i][4] = String.valueOf(award.getLevel());
			StringDate date = new StringDate();
			columnNames[i][5] = date.DateToString(award.getDate());
			columnNames[i][6] = String.valueOf(award.getEmpowerUnit());
		}
		int[] px = new int[]{40,120,105,50,50,80,80};
		JTableDefine d = new JTableDefine();
		d.printTable(columnNames,px);
		System.out.println("============================");
		return "success";
	}
}
